package com.zzh.test.parser;

import com.zzh.test.bean.User;
import org.nd4j.linalg.io.StringUtils;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.w3c.dom.Element;

/**
 * description: <br>
 * createTime: 2020/10/915:22 <br>
 *
 * @author zzh
 */
public class UserBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {

    @Override
    protected Class<?> getBeanClass(Element element) {
        return User.class;
    }


    @Override
    protected void doParse(Element element, BeanDefinitionBuilder bean) {
        String userName = element.getAttribute("userName");
        String email = element.getAttribute("email");
        if(StringUtils.hasText(userName)) {
            bean.addPropertyValue("userName", userName);
        }

        if(StringUtils.hasText(email)) {
            bean.addPropertyValue("email", email);
        }
    }
}
